<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="pro_list fr"  >
   <div class="title"  >
   	 <span class="titletxt">您现在的位置：</span>
     <ul> 
       <li class="root">会员中心</li>        
       <li>订单管理</li>  
       <li>退货申请</li>            
     </ul>
   </div>
  <c:if test="${not empty ret }">
   	<c:if test="${ret.code ne '200'}">
   		<script type="text/javascript">alertError('${ret.result}');</script>
   		<div id=messager class="messager" >
	         <div class="contentmsg">
	             <h5>提示信息～！</h5>
	             <ul>
	               <li>${ret.result}</li>
	             </ul>
	        </div>
	     <div class="closer" onClick="showHideLayer('messager');" title="关闭"></div>
	    </div>
   	</c:if>
   </c:if>
<br/>
<div  class="easyui-panel" title="退货申请列表"  style="">

<div data-options="region:'north',title:'',split:true" style="height:40px;background-color:#e4e4e4;">
    	<form action="" id="searchForm" name="searchForm">
    	<table>
    		<tr>
				<td class="screen-n"><span>订单编号</span></td>
				<td class="screen-n">
					<input type="text" id="orderCode" class="screen-input" onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>商品编号</span></td>
				<td class="screen-n">
					<input type="text" id="productCode" class="screen-input" onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>退货状态</span></td>
				<td class="screen-n">
					<select id="isReturn" class="easyui-combobox">
						<option value="">-全部-</option>
						<option value="0">-未退货-</option>
						<option value="1">-退货申请中-</option>
						<option value="2">-卖家不同意退货-</option>
						<option value="10">-已退货-</option>
					</select>
				</td>
				<td class="screen-n"><span>订单时间</span></td>
				<td class="screen-n">
					<input type="text" id="startDate" class="screen-input easyui-datebox" onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n"><span>至</span></td>
				<td class="screen-n">
					<input type="text" id="endDate" class="screen-input easyui-datebox" onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initProducts()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
				</td>
			</tr>
			</table>
		</form>
    </div>
    
    <div data-options="region:'center',split:true" style="width: 100%;height:431px">
		<table id="tableGrid" ></table>
	</div>
</div>
</div>
<script>
var toolbar = [{
	text:'申请退货',
    iconCls:'ext-icon-ruby_get',
    handler:function(){
    	var rows = productsTable.getCheckedData();
		if(rows==null || rows.length==0){
			alertWarning("请选中要申请退货的商品!");
			return;
		}
		if(confirm("确定申请退货?")){
			var codes = [];
			for(var i=0; i<rows.length; i++){
				if(rows[i].isReturn != 0){
					alertWarning("只能申请未退货的商品,请重新选择!");
					return;
				}else{
					codes.push(rows[i].productCode);
				}
			}
			var productCodeList = codes.toString();
			returnConfirmItem(productCodeList);
		}
    }
},
{
	text:'取消申请退货',
    iconCls:'ext-icon-ruby_put',
    handler:function(){
    	var rows = productsTable.getCheckedData();
		if(rows==null || rows.length==0){
			alertWarning("请选中要取消申请退货的商品!");
			return;
		}
		if(confirm("确定批量取消申请退货?")){
			var codes = [];
			for(var i=0; i<rows.length; i++){
				if(rows[i].isReturn != 1){
					alertWarning("只能选择退货申请中的商品,请重新选择!");
					return;
				}else{
					codes.push(rows[i].productCode);
				}
			}
			var productCodeList = codes.toString();
			var param = {"productCodeList":productCodeList,
					     "isReturn":0
					};
			$.pmsAjax({
				url:'<c:url value="/trade/item/updateMultipleConfirmItemForIsReturns.s"/>',
				data:param,
				success:function(data){
					if(data.code=="200"){
						layer.msg("批量取消申请退货成功！",1, {type: 1,shade: [0.2, '#ccc']});
						productsTable.refresh();
					}else{
						layer.alert(data.result, 8); 
					}
				}
			});
		}
    }
}];
var productsTable;
$(function(){
	initProducts();
});

function initProducts(){
	productsTable = $('#tableGrid').pDataGrid({
		 toolbar:toolbar,
		 columns:[[
				  {field:'ck',checkbox:true},
	          	  {field:'orderCode',title:'订单编号',align:'center',sortable:true,formatter:function(value,row){
						return '<a href="javascript:openOrderDetailWindow(\''+row.orderCode+'\')">'+value+'</a>';
		          }},
	          	  {field:'productCode',title:'商品编号',align:'center',sortable:true},
	          	  {field:'productName',title:'商品名称',align:'center',sortable:true},
	          	  {field:'createDateStr',title:'订单日期',align:'center',sortable:true},
	              {field:'priceUseType',title:'价格类型',align:'center',sortable:true},
	          	  {field:'salePrice',title:'价格(元)',align:'center',sortable:true},
	          	  {field:'confirmMoney',title:'确认金额(元)',align:'center',sortable:true},
	          	  {field:'isReturn',title:'退货状态',align:'center',sortable:true,formatter:function(value,row){
					 switch(row.isReturn){
					case 0:
						  return '未退货';
						  break;
					case 1:
						  return '退货申请中';
						  break;
					case 2:
						  return '卖家不同意退货';
						  break;
					case 10:
						  return '已退货';
						  break;
					}
		          }},
		          {field:'returnReason',title:'退货原因',align:'center',sortable:true},
		          {field:'refusedReturnReason',title:'卖家拒绝退货原因',align:'center',sortable:true}
		          //,
	              //{field:'action',title:'操作',align:'center',sortable:true,formatter:function(value,row){
		          //    var str = '';
			      //    if(row.isReturn==0){
			      //  	  str+='<img class="iconImg ext-icon-ruby_get" title="申请退货" onclick="returnConfirmItem(\''+row.productCode+'\');"/>&nbsp;';
				//	  }
			     //     if(row.isReturn==1){
			      //  	  str+='<img class="iconImg ext-icon-ruby_put" title="取消申请退货" onclick="cancelConfirmItemReturn(\''+row.productCode+'\');"/>&nbsp;';
				//	  }
				//	  return str;
		         //  }}
		          ]],
		    url:'<c:url value="/trade/item/searchPageOrderItemReturn.s"/>',  
		    pagination:true,
		    pageSize:30,
		    //singleSelect:false,
		    queryParams:{
		    	 "orderCode":$("#orderCode").val(),
		    	 "productCode":$("#productCode").val(),
		    	 "productName":$("#productName").val(),
				 "isReturn":$('#isReturn').combobox('getValue'),
				 "startDate":$("#startDate").datebox("getValue"),
				 "endDate":$("#endDate").datebox("getValue")
		    },
		    onDblClickRow:function(index,row){
		    	openOrderDetailWindow(row.orderCode);
			},
			completeCallback:function(data){
				if(data.code == "100"){
					alertError(data.result);
				}else{
					 
				}
			}
	}); 
}
function openOrderDetailWindow(code){
	var param = {"orderCode":code};
	$.pmsDialog({
		id:"win_order_detail",
		title:'订单号：'+code+" 明细",
		href:'<c:url value="/views/jsp/center/trade/order/order_detail.jsp"/>?printable=true',
		width:800,
		height:500,
		params:param,
		buttons:[]
	});
}
function returnConfirmItem(productCode){
	var param = {"productCode":productCode,
		     "isReturn":1
		};
	$.pmsDialog({
		id:"win_order_return_detail",
		title:"申请退货",
		href:'<c:url value="/views/jsp/center/trade/order/order_return_detail.jsp"/>?printable=true',
		width:500,
		height:260,
		params:param
	 
	});
}
function returnConfirmItem1(productCode){
	if(confirm('确认申请退货？')){
		var param = {"productCode":productCode,
				     "isReturn":1
				};
		$.pmsAjax({
			url:'<c:url value="/trade/item/updateConfirmItemForIsReturn.s"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					layer.msg("商品申请退货成功",1, {type: 1,shade: [0.2, '#ccc']});
					productsTable.refresh();
				}else{
					layer.alert(data.result, 8); 
				}
			}
		});
	} 
}

function cancelConfirmItemReturn(productCode){
	if(confirm('确认取消申请退货？')){
		var param = {"productCode":productCode,
				     "isReturn":0
				};
		$.pmsAjax({
			url:'<c:url value="/trade/item/updateConfirmItemForIsReturn.s"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					layer.msg("商品取消申请退货成功",1, {type: 1,shade: [0.2, '#ccc']});
					productsTable.refresh();
				}else{
					layer.alert(data.result, 8); 
				}
			}
		});
	} 
}
</script>